#ifndef REMOTE_UPGRADE_H
#define REMOTE_UPGRADE_H

#include <stdbool.h>
#include <time.h>
#include "connection/mqtt_client.h"

// 升级结果枚举
typedef enum {
    UPGRADE_SUCCESS = 0,
    UPGRADE_ERROR_DOWNLOAD_FAILED = -1,
    UPGRADE_ERROR_MD5_MISMATCH = -2,
    UPGRADE_ERROR_SCRIPT_FAILED = -3,
    UPGRADE_ERROR_INVALID_PARAMS = -4,
    UPGRADE_ERROR_MQTT_CONNECT_FAILED = -5
} upgrade_result_t;

// 升级状态枚举
typedef enum {
    UPGRADE_STATUS_IDLE = 0,
    UPGRADE_STATUS_CONNECTING,
    UPGRADE_STATUS_DOWNLOADING,
    UPGRADE_STATUS_DOWNLOADED,
    UPGRADE_STATUS_VERIFYING,
    UPGRADE_STATUS_VERIFIED,
    UPGRADE_STATUS_STARTING,
    UPGRADE_STATUS_RUNNING,
    UPGRADE_STATUS_SUCCESS,
    UPGRADE_STATUS_FAILED
} upgrade_status_t;

// 升级上下文
typedef struct {
    neu_mqtt_client_t *mqtt_client;
    const char *status_topic;
    upgrade_status_t current_status;
    const char *status_message;
    bool stop_reporting;
} upgrade_context_t;

/**
 * @brief 执行远程升级
 */
upgrade_result_t execute_remote_upgrade(
    const char* mqtt_broker,
    int mqtt_port,
    const char* mqtt_username,
    const char* mqtt_password,
    const char* status_topic,
    const char* download_url,
    const char* expected_md5,
    const char* upgrade_script
    );

#endif
